package operations;

import agent.BoatStates;
import agent.State;

public class LoadWolf implements Operation{
	
	@Override
	public State exec(State n) {
		if (!validOperation(n))
			return null;
		State ret = n.dupe();
		
		if (ret.isBoatLeft() && ret.isWolfLeft())
			ret.setWolfLeft(false);
		if (ret.isBoatRight() && ret.isWolfRight())
			ret.setWolfRight(false);
			
		ret.setBoatPassanger(BoatStates.wolf);
		
		return ret;
	}

	@Override
	public boolean validOperation(State n) {
		if (n.getBoatPassanger()!=BoatStates.empty)
			return false;
		if (n.isBoatLeft())
				if (!n.isWolfLeft())
					return false;
		if (n.isBoatRight())
			if (!n.isWolfRight())
				return false;
		return true;
	}

}
